/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.leospae.handler;


import java.util.HashMap;

import com.leospa.bean.Command_1;
import com.leospa.clients.DateClient;
import com.leospa.properties.CommandPropertiesFile;
import com.leospa.properties.ConfigPropertiesFile;

/**
 *
 * @author ADMIN
 */
public class Command_1_handler {
	
	public static void main(String[] args) {
//		String command0 = "CMD: 1; STATUS: OK; NAME : Test Test; CREDIT: 800; SOLARIUMID:1;SHOWPRICE:1";
//		if(command0 != null){
//			String data[] = command0.split(";");		
//			String result[] = data[1].split(":");
//			if(result[1].trim().equals("OK")){
//				
//				Command_1 command_1 = new Command_1();
//				
//				//Status
//				String status[] = data[1].split(":");
//				command_1.setStatus(status[1].trim());
//				
//				//Name
//				String name[] = data[2].split(":");
//				command_1.setName(name[1].trim());
//				
//				//Credit
//				String credit[] = data[3].split(":");
//				command_1.setCredit(credit[1].trim());
//				
//				//SOLARIUMID
//				String sol_id[] = data[4].split(":");
//				command_1.setSolarium_id(sol_id[1].trim());
//
//				//show price
//				String show_price[] = data[5].split(":");
//				command_1.setShow_price(show_price[1].trim());
//				
//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getName());
//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getCredit());
//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getShow_price());
//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getSolarium_id());
//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getStatus());
//
//			}
//		}
	}

	public int noOfLabel = 0;
	public static String massageRoomName2_1;
	public static String massageRoomName2_2;
	String[] parts2;
	public String sendCammand_1(String rfid_tag, String soloruim_id) {
		if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(ConfigPropertiesFile.SERVER_ADDRESS+","+ConfigPropertiesFile.PORT+", CMD:1;ID:"+rfid_tag+";SOLARIUMID:"+soloruim_id+"; ,"+ConfigPropertiesFile.TIMEOUT_MS);}
		String str = DateClient.SocketInterface(ConfigPropertiesFile.SERVER_ADDRESS,ConfigPropertiesFile.PORT, "CMD:1;ID:"+rfid_tag+";SOLARIUMID:"+soloruim_id+";", ConfigPropertiesFile.TIMEOUT_MS);

		if (str != null) {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(str);}
		} 

		return str;
	}

	public Command_1 get_command1(String rfid_tag, String soloruim_id) {
		String command0 = null;
		Command_1 command_1 = null;
		try {
			HashMap<String, String> hmap = new HashMap<String, String>();
			if (ConfigPropertiesFile.DEMO_MODE == true) {
				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(ConfigPropertiesFile.SERVER_ADDRESS+","+ConfigPropertiesFile.PORT+", CMD:1;ID:"+rfid_tag+";SOLARIUMID:"+soloruim_id+"; ,"+ConfigPropertiesFile.TIMEOUT_MS);}
				command0 = CommandPropertiesFile.Command_1;
			} else {
				command0= sendCammand_1(rfid_tag,soloruim_id);
				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Command 1 Info: "+command0);}
			}
			
			if(command0 != null){
				command_1 = new Command_1();
				String data[] = command0.split(";");		
				String result[] = data[1].split(":");
				if(result[1].trim().equals("OK")){
					
					
					//Status
					String status[] = data[1].split(":");
					command_1.setSTATUS(status[1].trim());
					
					//Name
					String name[] = data[2].split(":");
					command_1.setNAME(name[1].trim());
					
					//Credit
					String credit[] = data[3].split(":");
					command_1.setCREDIT(credit[1].trim());
					
					//SOLARIUMID
					String sol_id[] = data[4].split(":");
					command_1.setSOLARIUMID(sol_id[1].trim());
	
					//show price
					String show_price[] = data[5].split(":");
					command_1.setSHOWPRICE(show_price[1].trim());
					
	//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getName());}
	//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getCredit());}
	//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getShow_price());}
	//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getSolarium_id());}
	//				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_1.getStatus());}
	
				} else {
					String status[] = data[1].split(":");
					command_1.setSTATUS(status[1].trim());
					
				}
			}
		} catch (Exception e) {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){e.printStackTrace();}
		} finally{
			return command_1;
		}
			
	}
}
